#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export NO_PKG_MANGLE=1
export QA_RPATHS=$[ 0x0002 ]

DESTDIR = $(CURDIR)/debian/tmp

%:
	dh $@ --parallel --with autotools-dev,systemd

override_dh_auto_test:

override_dh_usrlocal:

override_dh_auto_configure:

override_dh_auto_build:
	export CC="ccache gcc -fsanitize=address" \
		&& export CFLAGS="-O1 -fno-omit-frame-pointer -g" \
		&& export ASAN_OPTIONS=detect_leaks=0 \
		&& ./configure \
  --prefix=/usr/local/openresty-asan/pcre \
  --libdir=/usr/local/openresty-asan/pcre/lib \
  --disable-cpp \
  --enable-jit \
  --enable-utf \
  --enable-unicode-properties \
		&& make -j`nproc` V=1 > /dev/stderr

override_dh_auto_install:
	make install DESTDIR=$(DESTDIR) \
		&& rm -rf $(DESTDIR)//usr/local/openresty-asan/pcre/bin \
		&& rm -rf $(DESTDIR)//usr/local/openresty-asan/pcre/share \
		&& rm -f  $(DESTDIR)//usr/local/openresty-asan/pcre/lib/*.la \
		&& rm -f  $(DESTDIR)//usr/local/openresty-asan/pcre/lib/*pcrecpp* \
		&& rm -f  $(DESTDIR)//usr/local/openresty-asan/pcre/lib/*pcreposix* \
		&& rm -rf $(DESTDIR)//usr/local/openresty-asan/pcre/lib/pkgconfig

override_dh_auto_clean:
	dh_clean
	rm -rf $(DESTDIR)

override_dh_strip:
	dh_strip --dbg-package=openresty-pcre-asan-dbgsym
